package com.telecomyt.jwportal.activity.conference;


import android.util.Log;

import com.telecomyt.jwportal.activity.camera.bean.CameraBean;
import com.telecomyt.jwportal.base.BasePresenter;
import com.telecomyt.jwportal.http.RetrofitManager;
import com.telecomyt.jwportal.utils.RxUtils;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;


public class ConferencePresenter extends BasePresenter<ConferenceContract.Model, ConferenceContract.View> implements ConferenceContract.Persenter {


    public ConferencePresenter(LifecycleProvider<ActivityEvent> provider) {
        super(provider);
    }

    @Override
    protected ConferenceContract.Model creatModule() {
        return null;
    }


    @Override
    public void getData(int type) {
        getView().showLoading();
        RetrofitManager.getInstance()
                .getDefaultReq()
                .musicRankingsDetails(type)
                .compose(getProvider().<CameraBean>bindUntilEvent(ActivityEvent.DESTROY))
                .compose(RxUtils.setThread())
                .subscribe(new Observer<CameraBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        Log.i("rxlife","--------onSubscribe");
                    }
                    @Override
                    public void onNext(CameraBean cameraBean) {
                        Log.i("rxlife","--------onNext");
                        getView().dismissLoading();
                        if (cameraBean != null) {
                            getView().setData(cameraBean);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.i("rxlife","--------onError");
                        getView().dismissLoading();

                    }

                    @Override
                    public void onComplete() {
                        Log.i("rxlife","--------onComplete");
                        getView().dismissLoading();
                    }
                });
    }
}
